package com.example.spark.controller;

import com.example.spark.entity.result.CommonResult;
import com.example.spark.service.impl.BackgroundServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@CrossOrigin
@RestController
@RequestMapping("/background")
public class BackgroundController {

    @Autowired
    private BackgroundServiceImpl backgroundService;

    @PostMapping(value = "/insertBackground")
    public CommonResult insertBackground(@RequestParam MultipartFile file) throws Exception {
        CommonResult commonResult = backgroundService.insertBackground(file);
        return commonResult;
    }

    @PutMapping(value = "/updateBackground/{id}")
    public CommonResult updateBackground(@RequestParam(required = false) MultipartFile file, @PathVariable Long id) throws Exception {
        CommonResult commonResult = backgroundService.updateBackground(file, id);
        return commonResult;
    }

    @GetMapping(value = "/selectBackground")
    public CommonResult selectBackground() {
        CommonResult commonResult = backgroundService.selectBackground();
        return commonResult;
    }

}
